<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<table id="app">
    <tr>
        <td>姓名</td>
        <td><input type="text" v-model="user.fullName" disabled></td>
    </tr>
    <tr>
        <td>邮箱：</td>
        <td><input type="text" v-model="user.email"></td>
    </tr>
    <tr>
        <td>手机号：</td>
        <td><input type="text" v-model="user.tel" disabled>
            <button @click="send" type="success" :disabled="!show">获取验证码<span v-show="!show" class="count">({{count}}s)</span></button>
        </td>
    </tr>
    <tr>
        <td>验证码：</td>
        <td><input type="text" v-model="user.code"></td>
    </tr>
    <tr>
        <td colspan="22">
            <input type="button" value="认证" @click="add()">
        </td>
    </tr>
</table>
<script src="script/vue.js"></script>
<script src="script/axios.min.js"></script>
<script src="script/moment.js"></script>
<script>
    new Vue({
        el:"#app",
        data:{
            user:{fullName:''},
            type:'',
            show: true, // 初始启用按钮
            count: '', // 初始化次数
            timer: null,
        },
        methods:{
            send() {
                if (!this.timer) {
                    this.count = 60;
                    this.show = false;
                    this.timer = setInterval(() => {
                        if (this.count > 0 && this.count <= 60) {
                            this.count--;
                        }else{
                            this.show = true;
                            clearInterval(this.timer); // 清除定时器
                            this.timer = null;
                        }
                    }, 1000)
                }
                axios.get("/api/finance-service-user/investor/sendemailcode/"+this.user.tel).then(
                    (res)=>{
                        if(res.data.success){
                            alert(res.data.message);
                        }else{
                            alert(res.data.message);
                        }
                    }
                );
            },
            add:function () {
                if(this.type==0){
                    axios.post("/api/finance-service-user/borrower/emailcheck",this.user).then(
                        (res)=>{
                            if(res.data.success){
                                alert(res.data.message);
                                window.location.href="个人中心-账户设置.html";
                            }else{
                                alert(res.data.message);
                            }
                        }
                    );
                }
                if(this.type==1){
                    axios.post("/api/finance-service-user/investor/emailcheck",this.user).then(
                        (res)=>{
                            if(res.data.success){
                                alert(res.data.message);
                                window.location.href="个人中心-账户设置.html";
                            }else{
                                alert(res.data.message);
                            }
                        }
                    );
                }
            }
        },
        mounted(){
            this.user=JSON.parse(sessionStorage.getItem("cususer"));
            this.type=sessionStorage.getItem("type");
        }

    });

</script>
</body>
</html>
